from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from django.contrib.auth.models import Group
from ..serializers.group import GroupListSerializer, NewPermissionListSerializer
from apps.meiduo_admin.utils import PageNum
from rest_framework.generics import ListAPIView
from .permission import Permission
from rest_framework.generics import GenericAPIView
from rest_framework.mixins import ListModelMixin


class GroupListView(ModelViewSet):

    queryset = Group.objects.all()
    serializer_class = GroupListSerializer
    pagination_class = PageNum

# 第一种方法
# class NewPermissionList(ListAPIView):
#
#     queryset = Permission.objects.all()
#     serializer_class = NewPermissionListSerializer


# 第二种方法 GenericAPIView自己单独使用
# class NewPermissionList(GenericAPIView):
#     queryset = Permission.objects.all()
#     serializer_class = NewPermissionListSerializer
#     def get(self, request):
#         instances = self.get_queryset()
#         serializer = self.get_serializer(instance=instances, many=True)
#         return Response(serializer.data)

# 第三种 GerenicAPIView集合MIXIN使用
class NewPermissionList(GenericAPIView, ListModelMixin):
    queryset = Permission.objects.all()
    serializer_class = NewPermissionListSerializer
    def get(self, requset):

        return self.list(requset)